package com.hospital.dao.impl;

import com.hospital.model.WardBedPatient;
import com.hospital.util.DruidUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * 病房床位患者关联数据访问对象
 * 处理与病房、床位和患者关联信息的数据库操作
 */
public class WardBedPatientDao {
    
    /**
     * 获取指定病房的所有床位信息
     * @param wardId 病房ID
     * @return 床位信息列表，包含床位状态和患者信息
     */
    public List<WardBedPatient> getWardBedsInfo(Integer wardId) {
        List<WardBedPatient> bedList = new ArrayList<>();
        String sql = "SELECT * FROM WardBedPatientView WHERE wardId = ?";
        
        try (Connection conn = DruidUtil.getConnection();
             PreparedStatement stmt = conn.prepareStatement(sql)) {
            
            stmt.setInt(1, wardId);
            ResultSet rs = stmt.executeQuery();
            
            while (rs.next()) {
                WardBedPatient bed = new WardBedPatient();
                bed.setWardId(rs.getInt("wardId"));
                bed.setBedId(rs.getInt("bedId"));
                bed.setBedNum(rs.getInt("bedNum"));
                bed.setBedStatus(rs.getInt("bedStatus"));
                bed.setPatientId(rs.getInt("patientId"));
                bed.setPatientName(rs.getString("patientName"));
                bedList.add(bed);
            }
            
        } catch (SQLException e) {
            e.printStackTrace();
        }
        
        return bedList;
    }
} 